package cn.zsc.netdisk.controller;

import cn.zsc.netdisk.response.Code;
import cn.zsc.netdisk.response.Result;
import cn.zsc.netdisk.service.MobileCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author ccying
 * @date 2021/3/11
 */
@RestController
@Slf4j
@RequestMapping("/send")
public class MobileCodeController {
    private final MobileCodeService service;

    public MobileCodeController(MobileCodeService service) {
        this.service = service;
    }

    /**
     * 请求获取手机验证码
     * @param mobileNumber 手机号码
     * */
    @CrossOrigin
    @GetMapping
    public Result send(@RequestParam String mobileNumber) {
        System.out.println("*************************************************");
        log.info("请求获取手机验证码");
        if (this.service.send(mobileNumber) == -1) {
            //获取失败
            return Result.fail(Code.ERROR);
        }
        return Result.success();
    }
}
